package com.book.dao;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class DataResource {
	
	private static List<String> dataList = new ArrayList<String>();
	
	URL fileUrl = DataResource.class.getResource("data.txt");
	
	static {
		InputStream inputStream = DataResource.class.getResourceAsStream("/data.txt");
		InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		String line = null;
		try {
			line =  bufferedReader.readLine();
			while (line != null) {
				if(line.isEmpty()) {
				} else {
					System.out.println("line:" + line);
					dataList.add(line);
				}
				line =  bufferedReader.readLine();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public List<String> getData(String string) {
		List<String> data = new ArrayList<String>();
		for(String sdata: dataList) {
			if(sdata.contains(string)) {
				data.add(sdata);
			}
		}
		System.out.println("data:" + data);
		return data;
	}

}
